//
//  Adapter.h
//  Archer
//
//  Created by wangdi on 12-10-10.
//
//

#ifndef __Archer__Adapter__
#define __Archer__Adapter__

#include "cocos2d.h"

namespace storm
{
    class Adapter
    {
    public:
        enum AdapterMode
        {
            MODE_NONE,
        };
    public:
        static Adapter *Instance();
        
        float PosScale() {return m_posScale;}
        float ResScale() {return m_resScale;}
        float UserScale() {return m_userScale;}
        
        void Init(cocos2d::CCSize sizeWorldDesign, float resScale = 1.0f, bool bHD = true);
        void EnableAdjustScreen(cocos2d::CCSize sizeBase);
        void EnableUserAdjust(cocos2d::CCPoint ptAdjust, float userScale);
        void EnableRetainaAdjust();
        
        void AdjustLayer(cocos2d::CCLayer *pLayer);
        
        cocos2d::CCPoint AdjustScreen(const cocos2d::CCPoint &pt);
        cocos2d::CCPoint AdjustRes(const cocos2d::CCPoint &pt);
        cocos2d::CCSize  AdjustRes(const cocos2d::CCSize &s);
        cocos2d::CCRect  AdjustRes(const cocos2d::CCRect &rc);
        float            AdjustRes(float f);
        
        cocos2d::CCPoint RestoreRes(const cocos2d::CCPoint &pt);
        cocos2d::CCSize  RestoreRes(const cocos2d::CCSize &s);
        cocos2d::CCRect  RestoreRes(const cocos2d::CCRect &rc);
        float            RestoreRes(float f);
        
        float            AdjustHD(float f);
        float            RestoreHD(float f);
        
        cocos2d::CCPoint ScreenCenter();
		cocos2d::CCSize  DesignSize() {return m_sizeDesign;}
    private:
        Adapter()
        : m_userScale(1.0f)
        , m_bHD(false)
        , m_hdScale(1.0f)
        , m_resScale(1.0f)
        , m_xScale(1.0f)
        , m_yScale(1.0f)
        , m_posScale(1.0f)
        {}
        
    public:
        bool             m_bHD;
        float            m_userScale;
        float            m_xScale;      // 同m_yScale只影响LAYER缩放 
        float            m_yScale;
        float            m_hdScale;     // 影响高清模式坐标 
        float            m_posScale;    // 影响坐标的比例 
        float            m_resScale;    // 资源缩放比例 
        cocos2d::CCSize  m_sizeDesign;   // 世界的大小 
        cocos2d::CCSize  m_sizeScreen;  // 屏幕大小 
        cocos2d::CCSize  m_sizeScreenPixel; // 像素大小 
        cocos2d::CCPoint m_ptAdjust;
    };
}

#define SCREEN_CENTER Adapter::Instance()->ScreenCenter()
#define ccpAdjustScreen(__X__,__Y__) Adapter::Instance()->AdjustScreen(cocos2d::CCPointMake((float)(__X__), (float)(__Y__)))

#define ccpAdjustRes(__X__,__Y__) Adapter::Instance()->AdjustRes(cocos2d::CCPointMake((float)(__X__), (float)(__Y__)))
#define ccsAdjustRes(_WIDTH_,_HEIGHT_) Adapter::Instance()->AdjustRes(cocos2d::CCSizeMake((float)(_WIDTH_),(float)(_HEIGHT_)))
#define ccrAdjustRes(__X__,__Y__,_WIDTH_,_HEIGHT_) Adapter::Instance()->AdjustRes(cocos2d::CCRectMake((float)(_X_),(float)(_Y_),(float)(_WIDTH_),(float)(_HEIGHT_)))

#define ccpRestoreRes(__X__,__Y__) Adapter::Instance()->RestoreRes(cocos2d::CCPointMake((float)(__X__), (float)(__Y__)))
#define ccsRestoreRes(_WIDTH_,_HEIGHT_) Adapter::Instance()->RestoreRes(cocos2d::CCSizeMake((float)(_WIDTH_),(float)(_HEIGHT_)))
#define ccrRestoreRes(__X__,__Y__,_WIDTH_,_HEIGHT_) Adapter::Instance()->RestoreRes(cocos2d::CCRectMake((float)(_X_),(float)(_Y_),(float)(_WIDTH_),(float)(_HEIGHT_)))

#define ccAdjustRes(_VALUE_) Adapter::Instance()->AdjustRes(_VALUE_)
#define ccRestoreRes(_VALUE_) Adapter::Instance()->RestoreRes(_VALUE_)

#define ccAdjustScreen(_VALUE_) Adapter::Instance()->AdjustScreen(_VALUE_)
#endif 
